<%-- 
    Document   : FRouteItinerary
    Created on : 01/05/2010, 12:30:02
    Author     : marcelo
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="br.terminalrodoviario.Route"%>
<%@page import="br.terminalrodoviario.City"%>
<%@page import="br.terminalrodoviario.RouteType"%>
<%@page import="br.terminalrodoviario.RouteItinerary"%>
<%@page import="java.util.*, java.text.*" %>
<jsp:useBean class="br.terminalrodoviario.Route" id="Route" scope="page"/>
<jsp:useBean class="br.terminalrodoviario.Company" id="company" scope="session"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%
            if (company.getId() == 0) {
                response.sendRedirect("../login.jsp");
            }
            String id = request.getParameter("id");
            if (id != null) {
                Route = new Route().selectById("Select r from Route r where r.id = " + id);
            }
%>
<html>
    <head>
        <title>Guia Terminal Rodoviário</title>
        <script type="text/javascript" src="../../add/js/cities.js"></script>
        <script type="text/javascript">
            var id = 0;            
            function add(hiddenCount){
                id += 1;
                hiddenCount.value = id;
                var form = document.getElementById("form");                
                var states = document.createElement("SELECT");
                states.name = "cboState"+id;
                states.id = "cboState"+id;
                states.setAttribute("onchange", "findCities(this.options[this.selectedIndex].value,'../../StateCityServlet','cboCity"+id+"')");
                states.setAttribute("class","calibri");
                states.setAttribute("style","width:50px;height:22px;");
                var estados = getEstados();
                for(var i = 0; i < estados.length; i++){
                    var str = estados[i].split("#");
                    states.options[i] = new Option(str[1],str[0]);
                }


                form.appendChild(states);
                form.innerHTML += "&nbsp;";
                var cities = document.createElement("SELECT");                
                cities.name = "cboCity"+id;
                cities.id = "cboCity"+id;
                cities.setAttribute("class","calibri");                
                cities.setAttribute("style","width:250px;");
                form.appendChild(cities);
                form.innerHTML += "<hr color='#CCCCCC'/>";
                findCities('AC','../../StateCityServlet','cboCity'+id);

            }
        </script>
        <style type="text/css">
            @import url("../../add/css/company.css");
            @import url("../../add/css/rodape.css");
        </style>
    </head>
    <body>
        <div class="geral">
            <table>
                <tr>
                    <td>
                        <div id="cabecalho">
                        </div>
                    </td>
                </tr>
            </table>
            <table id="menuAdmin" width="762">
                <tr >
                    <td align="center">
                        <ul class="menuRota" >
                            <li class="current"><a href="../Manager/MRoute.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuSolicitacao" >
                            <li><a href="../Manager/MSolicitation.jsp" /></li>
                        </ul>
                    </td>
                </tr>
            </table>

            <div style="float:left">
                <br/>
                <b><a href="../index.jsp">Início</a> -> <a href="../Manager/MRoute.jsp">Rotas</a> -> <a href="FRouteItinerary.jsp">Cadastrar Itinerário</a></b>
                <br/><br/>
            </div>
            <div align="right" style="font-family:calibri; font-size:11px; font-style:inherit">
                <br/>Bem-vindo <b><%=request.getSession().getAttribute("username")%></b>,<br/>
                você está logado desde <%=request.getSession().getAttribute("date_session")%>h. ( <a href="../logout.jsp"><b>Logout</b></a> )<br/><br/>
            </div>

            <table  id="subTitulo">
                <tr>
                    <td id="icone">
                        &nbsp;&nbsp;&nbsp;&nbsp;<img align="center" src="../../add/images/icones/route.png" alt="Rotas" title="Rotas"/>
                    </td>
                    <td>
                        Itinerário
                    </td>
                </tr>
            </table>
            <form id="frm" action="../RouteItineraryServlet" method="get">
                <table id="subMenu">
                    <tr>
                        <td>
                            <ul class="btNovo2" >
                                <li><a href=""/></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btEditar" >
                                <li><input id="btnEditar" type=image src="../../add/images/botoes/btEditarDisable.png" value="Editar" disabled="true" name="edit" title="Editar" alt="Editar"/></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btRemover" >
                                <li><input id="btnRemover" type=image src="../../add/images/botoes/btRemoverDisable.png" value="Remover" disabled="true" name="delete" title="Remover" alt="Remover"/></li>
                            </ul>
                        </td>
                         <td>
                            <ul class="btAdicionar" >
                                <li><img style="cursor:pointer;" src="../../add/images/botoes/btAdicionar.png" value="Adicionar" onclick="javascript:add(document.getElementById('hiddenCount'));" title="Adicionar" alt="Adicionar"/></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btNovaVolta" >

                            </ul>
                        </td>

                    </tr>
                </table>
                <br/>
                <input type="hidden" value="0" name="hiddenCount" id="hiddenCount"/>
                <input type="hidden" value="<%=request.getParameter("id")%>" name="id" id="id"/>                
                <br/>
                <div style="width:305px">
                    <select class="calibri" name="cboState" style="width:50px; height:22px;" onchange="javascript:findCities(this.options[this.selectedIndex].value,'../../StateCityServlet','cboCityFrom');">
                        <option value="AC" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("AC") ? "selected='true'" : ""%>>AC</option>
                        <option value="AL" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("AL") ? "selected='true'" : ""%>>AL</option>
                        <option value="AM" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("AM") ? "selected='true'" : ""%>>AM</option>
                        <option value="AP" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("AP") ? "selected='true'" : ""%>>AP</option>
                        <option value="BA" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("BA") ? "selected='true'" : ""%>>BA</option>
                        <option value="CE" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("CE") ? "selected='true'" : ""%>>CE</option>
                        <option value="DF" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("DF") ? "selected='true'" : ""%>>DF</option>
                        <option value="ES" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("ES") ? "selected='true'" : ""%>>ES</option>
                        <option value="GO" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("GO") ? "selected='true'" : ""%>>GO</option>
                        <option value="MA" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("MA") ? "selected='true'" : ""%>>MA</option>
                        <option value="MT" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("MT") ? "selected='true'" : ""%>>MT</option>
                        <option value="MS" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("MS") ? "selected='true'" : ""%>>MS</option>
                        <option value="MG" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("MG") ? "selected='true'" : ""%>>MG</option>
                        <option value="PA" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("PA") ? "selected='true'" : ""%>>PA</option>
                        <option value="PB" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("PB") ? "selected='true'" : ""%>>PB</option>
                        <option value="PR" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("PR") ? "selected='true'" : ""%>>PR</option>
                        <option value="PE" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("PE") ? "selected='true'" : ""%>>PE</option>
                        <option value="PI" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("PI") ? "selected='true'" : ""%>>PI</option>
                        <option value="RJ" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("RJ") ? "selected='true'" : ""%>>RJ</option>
                        <option value="RN" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("RN") ? "selected='true'" : ""%>>RN</option>
                        <option value="RO" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("RO") ? "selected='true'" : ""%>>RO</option>
                        <option value="RS" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("RS") ? "selected='true'" : ""%>>RS</option>
                        <option value="RR" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("RR") ? "selected='true'" : ""%>>RR</option>
                        <option value="SC" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("SC") ? "selected='true'" : ""%>>SC</option>
                        <option value="SE" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("SE") ? "selected='true'" : ""%>>SE</option>
                        <option value="SP" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("SP") ? "selected='true'" : ""%>>SP</option>
                        <option value="TO" <%=Route.getFrom() != null && Route.getFrom().getState() != null && Route.getFrom().getState().equals("TO") ? "selected='true'" : ""%>>TO</option>
                    </select>
                    <select class="calibri" name="cboCityFrom" id="cboCityFrom" style="width:250px;">
                        <%
                                    int i = 0;
                                    for (City c : new City().select("select c from City c where c.removed = 0 and state = '" + (Route.getFrom() != null ? Route.getFrom().getState() : "AC") + "' or c.id = " + (Route.getFrom() != null ? Route.getFrom().getId() : 0) + "  order by c.state asc,c.name asc")) {
                        %>
                        <option value="<%=c.getId()%>"  <%=(Route.getFrom() != null && Route.getFrom().getId() == c.getId() ? "selected='true'" : "")%>><%=c.getName()%></option>
                        <%
                                    }
                        %>
                    </select>
                    <hr color="#CCCCCC"/>
                </div>
                <div id="form" style="width:305px">
                    <%
                                Collection<RouteItinerary> rtCities = new RouteItinerary().select("select rt from RouteItinerary rt where rt.route.id = " + id + " order by rt.sequence asc");
                                Object[] rts = rtCities.toArray();
                                //out.println(rts.length);
                                for (i = 1; i < (rts.length - 1); i++) {
                                    RouteItinerary rt = (RouteItinerary) rts[i];
                    %>

                    <div style="width:305px">
                        <select class="calibri" name="cboStateFrom" style="width:50px;" onchange="javascript:findCities(this.options[this.selectedIndex].value,'../../StateCityServlet','cboCity<%=i%>');">
                            <option value="AC" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("AC") ? "selected='true'" : ""%>>AC</option>
                            <option value="AL" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("AL") ? "selected='true'" : ""%>>AL</option>
                            <option value="AM" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("AM") ? "selected='true'" : ""%>>AM</option>
                            <option value="AP" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("AP") ? "selected='true'" : ""%>>AP</option>
                            <option value="BA" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("BA") ? "selected='true'" : ""%>>BA</option>
                            <option value="CE" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("CE") ? "selected='true'" : ""%>>CE</option>
                            <option value="DF" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("DF") ? "selected='true'" : ""%>>DF</option>
                            <option value="ES" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("ES") ? "selected='true'" : ""%>>ES</option>
                            <option value="GO" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("GO") ? "selected='true'" : ""%>>GO</option>
                            <option value="MA" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("MA") ? "selected='true'" : ""%>>MA</option>
                            <option value="MT" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("MT") ? "selected='true'" : ""%>>MT</option>
                            <option value="MS" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("MS") ? "selected='true'" : ""%>>MS</option>
                            <option value="MG" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("MG") ? "selected='true'" : ""%>>MG</option>
                            <option value="PA" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("PA") ? "selected='true'" : ""%>>PA</option>
                            <option value="PB" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("PB") ? "selected='true'" : ""%>>PB</option>
                            <option value="PR" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("PR") ? "selected='true'" : ""%>>PR</option>
                            <option value="PE" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("PE") ? "selected='true'" : ""%>>PE</option>
                            <option value="PI" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("PI") ? "selected='true'" : ""%>>PI</option>
                            <option value="RJ" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("RJ") ? "selected='true'" : ""%>>RJ</option>
                            <option value="RN" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("RN") ? "selected='true'" : ""%>>RN</option>
                            <option value="RO" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("RO") ? "selected='true'" : ""%>>RO</option>
                            <option value="RS" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("RS") ? "selected='true'" : ""%>>RS</option>
                            <option value="RR" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("RR") ? "selected='true'" : ""%>>RR</option>
                            <option value="SC" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("SC") ? "selected='true'" : ""%>>SC</option>
                            <option value="SE" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("SE") ? "selected='true'" : ""%>>SE</option>
                            <option value="SP" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("SP") ? "selected='true'" : ""%>>SP</option>
                            <option value="TO" <%=rt.getCity() != null && rt.getCity().getState() != null && rt.getCity().getState().equals("TO") ? "selected='true'" : ""%>>TO</option>
                        </select>
                        <select class="calibri" name="cboCity<%=i%>" style="width:250px;">
                            <%
                                                                Object[] cities = new City().select("select c from City c where c.state = '" + rt.getCity().getState() + "' or c.id =" + rt.getCity().getId()).toArray();
                                                                for (int j = 0; j < cities.length; j++) {
                                                                    City c = (City) cities[j];
                            %>
                            <option value="<%=c.getId()%>" <%=(rt.getCity().getId() == c.getId() ? "selected='true'" : "")%>>
                                <%=c.getName()%>
                            </option>
                            <%
                                                                }
                            %>
                            <script type="text/javascript">
                                id = <%=i%>;
                                document.getElementById("hiddenCount").value = id;
                            </script>
                        </select>
                    <hr color="#CCCCCC"/>
                    </div>
                    <%
                                }
                    %>
                </div>
                <div style="width:305px">
                    <select class="calibri" name="cboStateTo" style="width:50px;" onchange="javascript:findCities(this.options[this.selectedIndex].value,'../../StateCityServlet','cboCityTo');">
                        <option value="AC" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("AC") ? "selected='true'" : ""%>>AC</option>
                        <option value="AL" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("AL") ? "selected='true'" : ""%>>AL</option>
                        <option value="AM" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("AM") ? "selected='true'" : ""%>>AM</option>
                        <option value="AP" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("AP") ? "selected='true'" : ""%>>AP</option>
                        <option value="BA" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("BA") ? "selected='true'" : ""%>>BA</option>
                        <option value="CE" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("CE") ? "selected='true'" : ""%>>CE</option>
                        <option value="DF" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("DF") ? "selected='true'" : ""%>>DF</option>
                        <option value="ES" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("ES") ? "selected='true'" : ""%>>ES</option>
                        <option value="GO" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("GO") ? "selected='true'" : ""%>>GO</option>
                        <option value="MA" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("MA") ? "selected='true'" : ""%>>MA</option>
                        <option value="MT" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("MT") ? "selected='true'" : ""%>>MT</option>
                        <option value="MS" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("MS") ? "selected='true'" : ""%>>MS</option>
                        <option value="MG" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("MG") ? "selected='true'" : ""%>>MG</option>
                        <option value="PA" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("PA") ? "selected='true'" : ""%>>PA</option>
                        <option value="PB" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("PB") ? "selected='true'" : ""%>>PB</option>
                        <option value="PR" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("PR") ? "selected='true'" : ""%>>PR</option>
                        <option value="PE" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("PE") ? "selected='true'" : ""%>>PE</option>
                        <option value="PI" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("PI") ? "selected='true'" : ""%>>PI</option>
                        <option value="RJ" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("RJ") ? "selected='true'" : ""%>>RJ</option>
                        <option value="RN" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("RN") ? "selected='true'" : ""%>>RN</option>
                        <option value="RO" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("RO") ? "selected='true'" : ""%>>RO</option>
                        <option value="RS" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("RS") ? "selected='true'" : ""%>>RS</option>
                        <option value="RR" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("RR") ? "selected='true'" : ""%>>RR</option>
                        <option value="SC" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("SC") ? "selected='true'" : ""%>>SC</option>
                        <option value="SE" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("SE") ? "selected='true'" : ""%>>SE</option>
                        <option value="SP" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("SP") ? "selected='true'" : ""%>>SP</option>
                        <option value="TO" <%=Route.getTo() != null && Route.getTo().getState() != null && Route.getTo().getState().equals("TO") ? "selected='true'" : ""%>>TO</option>
                    </select>
                    <select class="calibri" name="cboCityTo" id="cboCityTo" style="width:250px; height:22px;">
                        <%
                                    i = 0;
                                    for (City c : new City().select("select c from City c where c.removed = 0 and state = '" + (Route.getTo() != null ? Route.getTo().getState() : "AC") + "' or c.id = " + (Route.getTo() != null ? Route.getTo().getId() : 0) + "  order by c.state asc,c.name asc")) {
                        %>
                        <option value="<%=c.getId()%>"  <%=(Route.getTo() != null && Route.getTo().getId() == c.getId() ? "selected='true'" : "")%>><%=c.getName()%></option>
                        <%
                                    }
                        %>
                    </select>
                </div>
                    <table>
                        <tr>
                            <td colspan="2" width="301" align="right">
                                <input type="submit" value="Gravar" />
                            </td>
                        </tr>
                    </table>
            </form>
            <br>
            <table id="rodape" style="background-image:url(../../add/images/rodape.png);">
                <tr>
                </tr>
            </table>
            <table id="btRodape" style="text-decoration: none;" >
                 <tr>
                    <td align="center" width="80px">
                        <ul class="btYoutube">
                            <li><a title="Youtube" href="http://www.youtube.com" /></li>
                        </ul>
                    </td >
                    <td align="center" width="80px">
                        <ul class="btOrkut">
                            <li><a title="Orkut" href="http://www.orkut.com" /></li>
                        </ul>
                    </td>
                    <td align="center" width="205px">
                        <ul class="btTwitter">
                            <li><a title="Twitter" href="http://twitter.com" /></li>
                        </ul>
                    </td>
                    <td align="center">
                        <a title="Trabalhe Conosco" class="text" href="../../Carrer.jsp" >Trabalhe Conosco</a>
                    </td>
                    <td align="center"  width="">
                        <a title="Mapa do Site" class="text" href="../../SiteMap.jsp">Mapa do Site</a>
                    </td>
                    <td align="center" width="">
                        <a title="Contatos" class="text" href="../../Contact.jsp">Contatos</a>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>
